home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_217 / stevie / screen.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  150 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. /*
  12.  * The following variable is set (in cursupdate) to the number of physical
  13.  * lines taken by the line the cursor is on. We use this to avoid extra calls
  14.  * to plines(). The optimized routine updateline() makes sure that the size of
  15.  * the cursor line hasn't changed. If so, lines below the cursor will move up
  16.  * or down and we need to call the routine s_refresh() to examine the
  17.  * entire screen. 
  18.  */
  19. static int      Cline_size;    /* size (in rows) of the cursor line */
  20. static int      Cline_row;    /* starting row of the cursor line */
  21.  
  22. /*
  23.  * updateline() - like s_refresh() but only for cursor line 
  24.  *
  25.  * This determines whether or not we need to call s_refresh() to examine
  26.  * the entire screen for changes. This occurs if the size of the cursor line
  27.  * (in rows) has changed.
  28.  */
  29. static void
  30. updateline()
  31. {
  32.     char           *ptr;
  33.     int             col;
  34.     int             size;
  35.     int             j;
  36.  
  37.     if (RedrawingDisabled)    /* Is this the correct action ? */
  38.     return;
  39.  
  40.     ptr = format_line(Curschar->linep->s, &col);
  41.  
  42.     size = 1 + ((col - 1) / Columns);
  43.     if (Cline_size == size) {
  44.     outstr(T_CI);
  45.     windgoto(Cline_row, 0);
  46.     if (P(P_NU)) {
  47.         /*
  48.          * This should be done more efficiently. 
  49.          */
  50.         outstr(mkline(cntllines(Filemem, Curschar)));
  51.     }
  52.     outstr(ptr);
  53.  
  54.     j = col + (P(P_NU) ? 8 : 0);
  55.     col = j % Columns;
  56.     if ((col != 0) || (j == 0)) {
  57. #ifdef T_END_L
  58.         windgoto(Cline_row + size - 1, col);
  59.         outstr(T_END_L);
  60. #else
  61.         for (; col < Columns; col++)
  62.         outchar(' ');
  63. #endif
  64.     }
  65.     outstr(T_CV);
  66.     } else {
  67.     s_refresh(VALID_TO_CURSCHAR);
  68.     }
  69. }
  70.  
  71. void
  72. cursupdate(type)
  73.     int             type;
  74. {
  75.     register char   c;
  76.     register int    incr;
  77.     register int    i;
  78.     register int    didincr;
  79.  
  80.     if (MustUpdateBotchar == TRUE)
  81.     Update_Botchar();
  82.  
  83.     if (NumLineSizes < 0) {
  84.     s_refresh(NOT_VALID);
  85.     } else {
  86.         if (LineNotValid == TRUE)
  87.         updateline();
  88.  
  89.     if (type != UPDATE_CURSOR) {
  90.         s_refresh(type);
  91.         } else if (ValidToCurschar == TRUE) {
  92.         s_refresh(VALID_TO_CURSCHAR);
  93.         } else if (CheckTopcharAndBotchar == TRUE) {
  94.         s_refresh(VALID);
  95.         }
  96.     }
  97.  
  98.     CheckTopcharAndBotchar = FALSE;
  99.     MustUpdateBotchar = FALSE;
  100.     ValidToCurschar = FALSE;
  101.     LineNotValid = FALSE;
  102.  
  103.     Cursrow = Curscol = Cursvcol = i = 0;
  104.     for (i = 0; i < NumLineSizes; i++) {
  105.     if (LinePointers[i] == Curschar->linep)
  106.         break;
  107.     Cursrow += LineSizes[i];
  108.     }
  109.  
  110.     if (P(P_NU))
  111.     Curscol = 8;
  112.  
  113.     Cline_row = Cursrow;
  114.     Cline_size = LineSizes[i];
  115.  
  116.     for (i = 0; i <= Curschar->index; i++) {
  117.     c = Curschar->linep->s[i];
  118.     /* A tab gets expanded, depending on the current column */
  119.     if (c == TAB && !P(P_LS))
  120.         incr = P(P_TS) - (Cursvcol % P(P_TS));
  121.     else
  122.         incr = chars[c].ch_size;
  123.     Curscol += incr;
  124.     Cursvcol += incr;
  125.     if (Curscol >= Columns) {
  126.         Curscol -= Columns;
  127.         Cursrow++;
  128.         didincr = TRUE;
  129.     } else
  130.         didincr = FALSE;
  131.     }
  132.     if (didincr)
  133.     Cursrow--;
  134.  
  135.     if (c == TAB && State == NORMAL && !P(P_LS)) {
  136.     Curscol--;
  137.     Cursvcol--;
  138.     } else {
  139.     Curscol -= incr;
  140.     Cursvcol -= incr;
  141.     }
  142.     if (Curscol < 0)
  143.     Curscol += Columns;
  144.  
  145.     if (set_want_col) {
  146.     Curswant = Cursvcol;
  147.     set_want_col = FALSE;
  148.     }
  149. }
  150.